package process;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

import org.hibernate.SessionFactory;


@WebListener
public class InitServlet implements ServletContextListener {
	
	private static final String ATT_SESS_FACTORY = "sessionFactory";
    private SessionFactory sessionFactory;

	@SuppressWarnings( "deprecation" )
    @Override
	public void contextInitialized(ServletContextEvent arg0) {

		ServletContext servletContext = arg0.getServletContext();
		sessionFactory = new org.hibernate.cfg.Configuration().configure().buildSessionFactory();
		servletContext.setAttribute(ATT_SESS_FACTORY, this.sessionFactory);
		System.out.print("init process ********************************");
	}

	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
		sessionFactory.close();

	}

}
